package ui.phone

import androidx.compose.runtime.mutableStateOf
import kotlinx.coroutines.CoroutineScope
import model.repository.UserRepository
import model.vo.MessageListItem
import state.ApplicationWindowsState
import state.WindowType


/**
 * @author wei kunJie
 * @date 2024/4/26 13:42:18
 */
class PhoneViewModel(applicationWindowsState: ApplicationWindowsState, coroutineScope: CoroutineScope) {
    val applicationWindowsState: ApplicationWindowsState
    val coroutineScope: CoroutineScope

    //头像
    val avatar = mutableStateOf("")

    //是否打开的麦克风
    val isMicrophone = mutableStateOf(false)

    //是否打开了听筒
    val isVoice = mutableStateOf(false)

    //通话状态
    val phoneState = mutableStateOf("正在连接...")

    /**
     * 通话窗口初始化方法
     */
    init {
        this.applicationWindowsState = applicationWindowsState
        this.coroutineScope = coroutineScope
        avatar.value = PoneUser.messageListItem?.headImage ?: ""
        //在这里开启通话
    }

    //打开或关闭麦克风
    fun closeOrOpenMicrophone() {
        isMicrophone.value = !isMicrophone.value
    }

    //打开或关闭听筒
    fun closeOrOpenVoice() {
        isVoice.value = !isVoice.value
    }

    //结束通话
    fun closePhone() {
        phoneState.value = "结束通话"
        applicationWindowsState.close(WindowType.Phone)//关闭窗口
    }
}
//通话对象信息，和哪个用户进行通话
object PoneUser{
    var messageListItem:MessageListItem?=null
}